1 *SPACE WAR GAME - BY JEFFREY STANTON 2 ORG $4000 3 *ZERO PAGE EQUATES 4 SHPL EQU $F0 5 SHPH EQU $F1 6 SHPML EQU $F2 7 SHPMH EQU $F3 8 SHPMOL EQU $F4 9 SHPMOH EQU $F5 10 SL EQU $F6 11 SH EQU $F7 12 *PLAYER MISSILE EQUATES 13 PMBASE EQU $D407 14 PDATA EQU $8800 15 GRACTL EQU $D01D 16 DMACTL EQU $22F 17 SIZEP0 EQU $D008 18 SIZEP1 EQU $D009 19 COLPM0 EQU $2C0 20 COLPM1 EQU $2C1 21 HPOSP0 EQU $D000 22 HPOSP1 EQU $D001 23 HPOSM0 EQU $D004 24 HPOSM1 EQU $D005 25 PMADR EQU $C0 26 HITCLR EQU $D01E 27 *COLLISIONS 28 M0PL EQU $D008 29 M1PL EQU $D009 30 P0PL EQU $D00C 31 *MISC EQUATES 32 NDLIST EQU $9400 ; ADR OF NEW DISPLAY LIST 33 SCREEN EQU $9000 34 COLOR0 EQU $2C4 35 COLOR2 EQU $2C6 36 COLOR4 EQU $2C8 37 SETVBK EQU $E45C 38 XITVBK EQU $E462 39 STRIG0 EQU $284 40 STICK EQU $278 41 RANDOM EQU $D20A 42 AUDF1 EQU $D200 43 AUDC1 EQU $D201 44 AUDF2 EQU $D202 45 AUDC2 EQU $D203 46 *DATA 4000 080808 47 SHAPEO HEX 0808081C1C1C3E3E22220000 400C 000001 48 HEX 0000010E1E2E040408000000 4018 000000 49 HEX 000000703C3F3C7000000000 4024 000008 50 HEX 00000804042E1E0E01000000 4030 002222 51 HEX 0022223E3E1C1C1C08080800 403C 000008 52 HEX 00000810103A3C3840000000 4048 000000 53 HEX 000000071E7E1E0700000000 4054 000040 54 HEX 000040383C3A101008000000 4060 000C18 55 SHPLO HEX 000C1824303C4854 4068 020201 56 MSHAPE HEX 0202010203000201 4070 020201 57 HEX 0202010203000201 4078 080804 58 HEX 080804080C000804 4080 080804 59 HEX 080804080C000804 4088 686A6C 60 MISLO HEX 686A6C6E70727476 4090 787A7C 61 MISLO1 HEX 787A7C7E80828486 4098 010203 62 SKFLAG HEX 0102030405050504030201 40A3 707070 63 DLIST HEX 7070704700900202 40AB 020202 64 HEX 0202020202020202 40B3 020202 65 HEX 0202020202020202 40BB 020202 66 HEX 0202020202410094 40C3 000101 67 VTX HEX 0001010100FFFFFF ; THRUST VECTORS 40CB FFFF00 68 VTY HEX FFFF0001010100FF 40D3 332829 69 SCLINE HEX 33282930031100101000 ; SCORE LINE DATA 40DD 003328 70 HEX 00332829300312001010 40E7 DDDD6B 71 DERES HEX DDDD6B6BAAAAE6E6 40EF 5555AA 72 HEX 5555AAAA4A4A3535 40F7 4A4A64 73 HEX 4A4A646492922525 40FF 111148 74 HEX 11114848 75 *VARIABLES 4103 00 76 VX DB 0 ; SHIP VELOCITY-HORIZ. 4104 00 77 VX1 DB 0 4105 00 78 VY DB 0 ; SHIP VELOCITY-VERT. 4106 00 79 VY1 DB 0 4107 00 80 VXP DB 0 ; SHIP VELOCITY-ALTERNATIVE 4108 00 81 VXP1 DB 0 4109 00 82 VYP DB 0 410A 00 83 VYP1 DB 0 410B 00 84 XPM0 DS 1 ; CURRENT X POS SHIP 410C 00 85 XPM1 DS 1 410D 0A 86 YOLDPM0 DB 10 ; OLD Y POS SHIP 410E 0A 87 YOLDPM1 DB 10 410F 00 88 YMISOLD0 DS 1 ; OLD MISSILE Y POS 4110 00 89 YMISOLD1 DS 1 4111 00 90 YPM0 DS 1 ; CURRENT Y POS SHIP 4112 00 91 YPM1 DS 1 4113 00 92 DIR DB 0 ; SHIP DIRECTION 4114 00 93 DIR1 DB 0 4115 00 94 DIRM0 DS 1 ; MISSILE TRAVEL DIRECTION 4116 00 95 DIRM1 DS 1 4117 00 96 COUNT DB 0 ; COUNTER FOR JOYSTICK 4118 00 97 SCRCNTX DB 0 ; SCREEN X COUNTERS 4119 01 98 SCRCNTX1 DB 1 411A 00 99 SCRCNTY DB 0 ; SCREEN Y COUNTERS 411B 01 100 SCRCNTY1 DB 1 411C 00 101 FLAG DS 1 ; STICK BACK FLAG 411D 00 102 SKIPX DS 1 ; CONTROLS RATE OF SHIP UPDATE - HORIZ. 411E 00 103 SKIPX1 DS 1 411F 00 104 SKIPY DS 1 ; CONTROLS RATE OF SHIP UPDATE - VERT. 4120 00 105 SKIPY1 DS 1 4121 00 106 MASK DS 1 4122 FC 107 MASK0 DB $FC ; MISSILE MASKS 4123 F3 108 MASK1 DB $F3 4124 00 109 XMIS0 DS 1 ; HORIZ MISSILE POSITIONS 4125 00 110 XMIS1 DS 1 4126 00 111 YMIS0 DS 1 ; VERTICAL MISSILE POSITIONS 4127 00 112 YMIS1 DS 1 4128 00 113 TMIS0 DS 1 ; MISSILE TIMERS 4129 00 114 TMIS1 DS 1 412A 00 115 SCORE0D DS 1 ; DIGITS 412B 00 116 SCORE0T DS 1 ; TENS 412C 00 117 SCORE1D DS 1 412D 00 118 SCORE1T DS 1 412E 00 119 EXCOUNT DS 1 412F 00 120 KILL0 DS 1 ; KILL FLAG 4130 00 121 KILL1 DS 1 4131 0000 122 MBANG DS 2 ; SOUND COUNTERS-MISSILES 4133 00 123 SBANG DS 1 ; SOUND COUNTER 4134 000000 124 DEREZ DS 12 ; TEMP STORAGE DURING DEREZ ROUTINE 125 START 126 *SETUP DLIST 4140 A900 127 LDA #$00 ; NORMAL WIDTH 4142 8D09D0 128 STA SIZEP1 4145 A200 129 LDX #$00 4147 BDA340 130 DLOOP LDA DLIST,X 414A 9D0094 131 STA NDLIST,X 414D E8 132 INX 414E E020 133 CPX #$20 ; 32 ELEMENTS 4150 D0F5 134 BNE DLOOP 4152 A900 135 LDA #>NDLIST 4154 8D3002 136 STA 560 4157 A994 137 LDA #SCREEN ; SETUP POINTERS TO CLEAR SCREEN 415E 85F6 141 STA SL 4160 A990 142 LDA #FRAME ; LO BYTE 4201 205CE4 221 JSR SETVBK 4204 A900 222 LDA #$00 223 *READ STICK 4206 4C0642 224 FOREVER JMP FOREVER 4209 EA 225 FRAME NOP 226 *READ STICK EVERY 6 TIMES 420A EE1741 227 CHKSTK INC COUNT 420D AD1741 228 LDA COUNT 4210 C905 229 CMP #05 ; READ STICK ONLY EVERY 6TH TIME 4212 F003 230 BEQ AA4 4214 4C2842 231 JMP P1 232 *SETUP CALL TO JOYSTICK-PLAYER 0 4217 A200 233 AA4 LDX #$00 ; PLAYER 0 4219 BD0741 234 LDA VXP,X ; SET PLAYER'S NEW VELOCITY TO OLD VELOCITY 421C 8D0341 235 STA VX 421F BD0941 236 LDA VYP,X 4222 8D0541 237 STA VY 4225 202C43 238 JSR JOYSTK 239 *UPDATE X & Y POSITIONS PLAYER #0 4228 A200 240 P1 LDX #$00 422A 20A643 241 JSR UPDAT 242 *.5 422D 204244 243 JSR PLSET0 ; PLOT PLAYER 0 4230 208244 244 JSR PLOT 4233 A5F4 245 LDA SHPMOL ; STORE AS OLD Y POS FOR NEXT CYCLE 4235 8D0D41 246 STA YOLDPM0 4238 AD1741 247 CKSTK1 LDA COUNT 423B C906 248 CMP #$06 ; READ STICK ONLY EVERY 6TH TIME 423D F003 249 BEQ AB4 423F 4C5842 250 JMP P2 251 *SETUP CALL TO JOYSTICK-PLAYER 1 4242 A201 252 AB4 LDX #$01 ; PLAYER 1 4244 BD0741 253 LDA VXP,X 4247 8D0341 254 STA VX 424A BD0941 255 LDA VYP,X 424D 8D0541 256 STA VY 4250 202C43 257 JSR JOYSTK 4253 A900 258 LDA #$00 ; RESET 4 CYCLE COUNTER 4255 8D1741 259 STA COUNT 260 *UPDATE X & Y POSITIONS PLAYER #1 4258 A201 261 P2 LDX #$01 425A 20A643 262 JSR UPDAT 263 *.5 425D 206244 264 JSR PLSET1 ; PLOT PLAYER 1 4260 208244 265 JSR PLOT 4263 A5F4 266 LDA SHPMOL ; STORE AS OLD Y POS FOR NEXT CYCLE 4265 8D0E41 267 STA YOLDPM1 268 *FIRE MISSILE 4268 A200 269 LDX #$00 426A 200B45 270 JSR MISSILE 426D A201 271 LDX #$01 426F 200B45 272 JSR MISSILE 273 *CHECK COLLISION 274 *CHECK FOR OLD COLLISION FIRST 4272 AD2F41 275 LDA KILL0 ; FIRST TEST FOR 2 PLAYER COLLISION 4275 C900 276 CMP #$00 4277 F007 277 BEQ AB10 ; CAN'T BE 2 PLAYER COLLISION 4279 AD3041 278 LDA KILL1 427C C900 279 CMP #$00 427E D024 280 BNE REMOVE 4280 AD3041 281 AB10 LDA KILL1 ; TEST FOR DERES PLAYER#I 4283 C900 282 CMP #$00 4285 D031 283 BNE REMOV1 4287 AD2F41 284 LDA KILL0 ; TEST FOR DERES PLAYER#O 428A C900 285 CMP #$00 428C D03D 286 BNE REMOV0 287 *CHECK FOR NEW COLLISION 428E AD0CD0 288 LDA P0PL ; TEST P#O AGAINST P#1 4291 D011 289 BNE REMOVE 4293 AD08D0 290 LDA M0PL ; TEST M#O AGAINST P#1 4296 C902 291 CMP #$02 4298 F01E 292 BEQ REMOV1 429A AD09D0 293 LDA M1PL ; TEST M#1 AGAINST P#O 429D C901 294 CMP #$01 429F F02A 295 BEQ REMOV0 42A1 4CDB42 296 JMP TESTE 42A4 A901 297 REMOVE LDA #01 42A6 8D2F41 298 STA KILL0 42A9 8D3041 299 STA KILL1 42AC 20DB45 300 JSR EXPLO0 42AF 20E745 301 JSR EXPLO1 42B2 EE2E41 302 INC EXCOUNT ; NEXT EXPLOSION FRAME 42B5 4CDB42 303 JMP TESTE ; TEST IF EXPLOSION FINISHED 42B8 A901 304 REMOV1 LDA #$01 42BA 8D3041 305 STA KILL1 42BD A9F0 306 LDA #$F0 ; PUT MISSILE OFF SCREEN 42BF 8D05D0 307 STA HPOSM1 42C2 20E745 308 JSR EXPLO1 42C5 EE2E41 309 INC EXCOUNT 42C8 4CDB42 310 JMP TESTE 42CB A901 311 REMOV0 LDA #$01 42CD 8D2F41 312 STA KILL0 42D0 A9F0 313 LDA #$F0 ; PUT MISSILE OFF SCREEN 42D2 8D04D0 314 STA HPOSM0 42D5 20DB45 315 JSR EXPLO0 42D8 EE2E41 316 INC EXCOUNT 42DB AD2E41 317 TESTE LDA EXCOUNT ; TEST IF DONE WITH DERES CYCLE 42DE C930 318 CMP #$30 42E0 D041 319 BNE ENDCYCLE 42E2 A900 320 LDA #$00 ; SHUT OFF EXPLOSION SOUND 42E4 8D01D2 321 STA AUDC1 42E7 8D03D2 322 STA AUDC2 42EA 8D3341 323 STA SBANG 42ED 203946 324 JSR SCORE ; UPDATE SCORE 42F0 A900 325 LDA #$00 ; RESET 42F2 8D2E41 326 STA EXCOUNT 42F5 8D2F41 327 STA KILL0 42F8 8D3041 328 STA KILL1 329 *REPOSITION SHIP AFTER KILL 42FB A950 330 LDA #$50 ; SHIP 0 42FD 8D0B41 331 STA XPM0 4300 8D00D0 332 STA HPOSP0 4303 A965 333 LDA #$65 4305 8D1141 334 STA YPM0 4308 A9A0 335 LDA #$A0 ; SHIP 1 430A 8D0C41 336 STA XPM1 430D 8D01D0 337 STA HPOSP1 4310 A985 338 LDA #$85 4312 8D1241 339 STA YPM1 4315 A900 340 LDA #$00 4317 8D0741 341 STA VXP 431A 8D0841 342 STA VXP1 431D 8D0941 343 STA VYP 4320 8D0A41 344 STA VYP1 4323 8D1ED0 345 ENDCYCLE STA HITCLR ; WRITING ANYTHING CLEARS COLLISION REGISIP 4326 208C46 346 JSR DOSOUND 4329 4C62E4 347 JMP XITVBK 348 * 349 *SUBROUTINE READ JOYSTICK 350 *INPUT X REG- # OF PLAYER 351 *VX,VY CURRENT PLAYER VELOCITY 352 *OUTPUT VXP,VYP PLAYER VELOCITY 432C BD7802 353 JOYSTK LDA STICK,X 432F 2902 354 AND #$02 ; DOWN BIT? 4331 D005 355 BNE CHKLF 4333 A901 356 LDA #01 4335 8D1C41 357 STA FLAG ; YES STICK BACK 4338 BD7802 358 CHKLF LDA STICK,X 433B 2904 359 AND #$04 ; LEFT BIT? 433D D012 360 BNE CHKRT 433F DE1341 361 DEC DIR,X 4342 BD1341 362 LDA DIR,X 4345 C9FF 363 CMP #$FF 4347 D005 364 BNE AC1 4349 A907 365 LDA #$07 ; SET DIR TO 7 434B 9D1341 366 STA DIR,X 434E 4C6843 367 AC1 JMP CHKFD 4351 BD7802 368 CHKRT LDA STICK,X 4354 2908 369 AND #$08 ; RIGHT BIT? 4356 D010 370 BNE CHKFD 4358 FE1341 371 INC DIR,X 435B BD1341 372 LDA DIR,X 435E C908 373 CMP #08 4360 D005 374 BNE AC2 4362 A900 375 LDA #$00 ; SET DIR TO 0 4364 9D1341 376 STA DIR,X 4367 EA 377 AC2 NOP 4368 BD7802 378 CHKFD LDA STICK,X 436B 2901 379 AND #$01 ; UP BIT? 436D D036 380 BNE AC9 381 *SET TO FREE FLOAT 436F BD1341 382 LDA DIR,X 4372 A8 383 TAY 4373 18 384 CLC 4374 B9C340 385 LDA VTX,Y ; GET X(DIR)THRUST VECTOR 4377 6D0341 386 ADC VX 437A C9FA 387 CMP #$FA 437C D002 388 BNE AC5 437E A9FB 389 LDA #$FB ; CLIP TO -5 4380 C906 390 AC5 CMP #$06 4382 D002 391 BNE AC6 4384 A905 392 LDA #$05 ; CLIP TO 5 4386 8D0341 393 AC6 STA VX ; STORE OLD OR CLIPPED VALUE 4389 9D0741 394 STA VXP,X 438C 18 395 CLC 438D B9CB40 396 LDA VTY,Y ; GET Y(DIR) THRUST VECTOR 4390 6D0541 397 ADC VY 4393 C9FA 398 CMP #$FA 4395 D002 399 BNE AC7 4397 A9FB 400 LDA #$FB ; CLIP TO -5 4399 C906 401 AC7 CMP #$06 439B D002 402 BNE AC8 439D A905 403 LDA #$05 ; CLIP TO 5 439F 8D0541 404 AC8 STA VY ; STORE OLD OR CLIPPED VALUE 43A2 9D0941 405 STA VYP,X 43A5 60 406 AC9 RTS 407 *SUBROUTINE TO UPDATE X & Y POSITIONS 43A6 EA 408 UPDAT NOP 409 *UPDATE Y POS, VARIABLE # TIMES 410 *TEST WHEN TO UPDATE 43A7 18 411 UPDATY CLC 43A8 BD0941 412 LDA VYP,X 43AB 6905 413 ADC #$05 ; SO NEGATIVE #'S IN TABLE TOO 43AD A8 414 TAY 43AE B99840 415 LDA SKFLAG,Y ; #TIMES TO SKIP IS RECIPRICAL OF SPEED 43B1 9D1F41 416 STA SKIPY,X 43B4 FE1A41 417 INC SCRCNTY,X ; INCREMENT Y COUNTER 43B7 BD1A41 418 LDA SCRCNTY,X 43BA DD1F41 419 CMP SKIPY,X ; IF MATCH UPDATE Y POS 43BD B003 420 BGE AD1 43BF 4CF143 421 JMP UPDATX 422 *UPDATE Y PLAYER POSITION 43C2 A900 423 AD1 LDA #$00 ; PERFORM Y UPDATE 43C4 9D1A41 424 STA SCRCNTY,X 43C7 BD0941 425 LDA VYP,X 43CA C900 426 CMP #$00 ; IF HASN'T MOVED DON'T UPDATE 43CC F023 427 BEQ UPDATX 43CE 3012 428 BMI AD2 43D0 FE1141 429 INC YPM0,X 43D3 BD1141 430 LDA YPM0,X 43D6 C9E0 431 CMP #$E0 ; HIT BOTTOM? 43D8 9005 432 BL AD3 43DA A918 433 LDA #$18 ; WRAP TO TOP 43DC 9D1141 434 STA YPM0,X 43DF 4CF143 435 AD3 JMP UPDATX 43E2 DE1141 436 AD2 DEC YPM0,X 43E5 BD1141 437 LDA YPM0,X 43E8 C918 438 CMP #$18 ; HIT TOP? 43EA B005 439 BGE UPDATX 43EC A9E0 440 LDA #$E0 ; WRAP TO BOTTOM 43EE 9D1141 441 STA YPM0,X 442 *UPDATE X POS VARIABLE # TIMES 43F1 18 443 UPDATX CLC 43F2 BD0741 444 LDA VXP,X 43F5 6905 445 ADC #05 ; SO NEG #'S IN TABLE TOO 43F7 A8 446 TAY 43F8 B99840 447 LDA SKFLAG,Y 43FB 9D1D41 448 STA SKIPX,X 43FE FE1841 449 INC SCRCNTX,X 4401 BD1841 450 LDA SCRCNTX,X 4404 DD1D41 451 CMP SKIPX,X ; UPDATESCREEN POSITION EVERY SKIP TIME 4407 B003 452 BGE AE1 4409 4C4144 453 JMP EE 454 *UPDATE X PLAYER POSITION 440C A900 455 AE1 LDA #$00 440E 9D1841 456 STA SCRCNTX,X 4411 BD0741 457 LDA VXP,X 4414 C900 458 CMP #$00 4416 F023 459 BEQ AE3 4418 3012 460 BMI AE2 441A FE0B41 461 INC XPM0,X 441D BD0B41 462 LDA XPM0,X 4420 C9D8 463 CMP #$D8 ; HIT RT SIDE? 4422 9005 464 BL AE4 4424 A928 465 LDA #$28 ; WRAP TO LEFT 4426 9D0B41 466 STA XPM0,X 4429 4C3B44 467 AE4 JMP AE3 442C DE0B41 468 AE2 DEC XPM0,X 442F BD0B41 469 LDA XPM0,X 4432 C928 470 CMP #$28 ; HIT LEFT? 4434 B005 471 BGE AE3 4436 A9D8 472 LDA #$D8 ; WRAP TO RIGHT 4438 9D0B41 473 STA XPM0,X 443B BD0B41 474 AE3 LDA XPM0,X ; NEW VALUE 443E 9D00D0 475 STA HPOSP0,X ; UPDATE ANTIC PLAYER HORIZ 4441 60 476 EE RTS 477 *PLOT PLAYER0 SETUP 4442 AD1141 478 PLSET0 LDA YPM0 ; CORRECTED YPOS 4445 85F2 479 STA SHPML 4447 A988 480 LDA #9 4644 C90A 719 CMP #$0A 4646 D008 720 BNE AM1 4648 EE2B41 721 INC SCORE0T ; INC TENS #0 464B A900 722 LDA #$00 464D 8D2A41 723 STA SCORE0D ; ZERO DIGITS #0 4650 AD3041 724 AM1 LDA KILL1 4653 F012 725 BEQ AM2 4655 EE2C41 726 INC SCORE1D ; INC DIGITS #1 4658 AD2C41 727 LDA SCORE1D 465B C90A 728 CMP #$0A 465D D008 729 BNE AM2 465F EE2D41 730 INC SCORE1T 4662 A900 731 LDA #$00 4664 8D2C41 732 STA SCORE1D 4667 AD2B41 733 AM2 LDA SCORE0T 466A 18 734 CLC 466B 6910 735 ADC #$10 466D 8D0790 736 STA SCREEN+7 ; PLACE IN SCREEN MEMORY 4670 AD2A41 737 LDA SCORE0D 4673 18 738 CLC 4674 6910 739 ADC #$10 4676 8D0890 740 STA SCREEN+8 4679 AD2D41 741 LDA SCORE1T 467C 18 742 CLC 467D 6910 743 ADC #$10 467F 8D1290 744 STA SCREEN+18 4682 AD2C41 745 LDA SCORE1D 4685 18 746 CLC 4686 6910 747 ADC #$10 4688 8D1390 748 STA SCREEN+19 468B 60 749 RTS 750 DOSOUND 468C AD2E41 751 LDA EXCOUNT ; SHIP EXPLODING? 468F F024 752 BEQ MSOUND ; NO? THEN GO CHECK FOR SHOT SOUNDS 4691 C901 753 CMP #$01 ; IS IT 1ST TIME 4693 D005 754 BNE AN1 4695 A940 755 LDA #$40 ; THIS WILL BE DIVIDED BY 4 SO 4697 8D3341 756 STA SBANG ; VOLUME GOES FROM $10 TO 0 IN STEPS OF EVERY 4 VBLANKS 469A CE3341 757 AN1 DEC SBANG 469D AD3341 758 LDA SBANG 46A0 4A 759 LSR 46A1 4A 760 LSR 46A2 09E0 761 ORA #$E0 ; LOWER IT 46A4 8D00D2 762 STA AUDF1 ; AUDF1 46A7 8D02D2 763 STA AUDF2 ; AUDF2 46AA 290F 764 AND #$0F ; KEEP VOLUME 46AC 8D01D2 765 STA AUDC1 ; DISTORTION 0 46AF 0980 766 ORA #$80 ; DISTORTION 8 46B1 8D03D2 767 STA AUDC2 46B4 60 768 RTS 769 MSOUND 46B5 A201 770 LDX #01 46B7 A002 771 LDY #02 ; AUDC1 & AUDC2 ARE 2 BYTES APART 46B9 BD3141 772 AP1 LDA MBANG,X 46BC F00E 773 BEQ AP2 ; IF 0 THEN NO SOUND 46BE DE3141 774 DEC MBANG,X ; LET IT COUNTDOWN TO 0 EVERY CYCLE 46C1 BD3141 775 LDA MBANG,X 46C4 9901D2 776 STA AUDC1,Y ; AUDC 46C7 A900 777 LDA #$00 46C9 9900D2 778 STA AUDF1,Y 46CC 88 779 AP2 DEY 46CD 88 780 DEY 46CE CA 781 DEX 46CF 10E8 782 BPL AP1 46D1 60 783 RTS